/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.boxin.ims.modules.wechat.entity.WechatMessageNear;
import com.boxin.ims.modules.wechat.dao.WechatMessageNearDao;

/**
 * 微信48小时信息Service
 * @author XiaoQian
 * @version 2014-05-08
 */
@Component
@Transactional(readOnly = true)
public class WechatMessageNearService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(WechatMessageNearService.class);
	
	@Autowired
	private WechatMessageNearDao wechatMessageNearDao;
	
	public WechatMessageNear get(Long id) {
		return wechatMessageNearDao.findOne(id);
	}
	
	public Page<WechatMessageNear> find(Page<WechatMessageNear> page, WechatMessageNear wechatMessageNear) {
		DetachedCriteria dc = wechatMessageNearDao.createDetachedCriteria();
		if (wechatMessageNear.getUser()!=null && wechatMessageNear.getUser().getId()>0){
			dc.add(Restrictions.eq("user.id", wechatMessageNear.getUser().getId()));
		}
		dc.addOrder(Order.desc("id"));
		return wechatMessageNearDao.find(page, dc);
	}
	
	
	public List<WechatMessageNear> findAll(){
		return (List<WechatMessageNear>) wechatMessageNearDao.findAll();
	}
	
	@Transactional(readOnly = false)
	public void save(WechatMessageNear wechatMessageNear) {
		wechatMessageNearDao.save(wechatMessageNear);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		wechatMessageNearDao.deleteById(id);
	}
	
}
